

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>List Objects &mdash; Python v2.7.8 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.7.8',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v2.7.8 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v2.7.8 documentation" href="../index.html" />
    <link rel="up" title="Concrete Objects Layer" href="concrete.html" />
    <link rel="next" title="Dictionary Objects" href="dict.html" />
    <link rel="prev" title="Tuple Objects" href="tuple.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
 
    

  </head>
  <body>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="dict.html" title="Dictionary Objects"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="tuple.html" title="Tuple Objects"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="http://www.python.org/">Python</a> &raquo;</li>
        <li>
          <a href="../index.html">Python v2.7.8 documentation</a> &raquo;
        </li>

          <li><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
          <li><a href="concrete.html" accesskey="U">Concrete Objects Layer</a> &raquo;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="list-objects">
<span id="listobjects"></span><h1>List Objects<a class="headerlink" href="#list-objects" title="Permalink to this headline">¶</a></h1>
<span class="target" id="index-0"></span><dl class="type">
<dt id="PyListObject">
<tt class="descname">PyListObject</tt><a class="headerlink" href="#PyListObject" title="Permalink to this definition">¶</a></dt>
<dd><p>This subtype of <a class="reference internal" href="structures.html#PyObject" title="PyObject"><tt class="xref c c-type docutils literal"><span class="pre">PyObject</span></tt></a> represents a Python list object.</p>
</dd></dl>

<dl class="var">
<dt id="PyList_Type">
<a class="reference internal" href="type.html#PyTypeObject" title="PyTypeObject">PyTypeObject</a> <tt class="descname">PyList_Type</tt><a class="headerlink" href="#PyList_Type" title="Permalink to this definition">¶</a></dt>
<dd><p>This instance of <a class="reference internal" href="type.html#PyTypeObject" title="PyTypeObject"><tt class="xref c c-type docutils literal"><span class="pre">PyTypeObject</span></tt></a> represents the Python list type.  This
is the same object as <tt class="docutils literal"><span class="pre">list</span></tt> in the Python layer.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_Check">
int <tt class="descname">PyList_Check</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*p</em><big>)</big><a class="headerlink" href="#PyList_Check" title="Permalink to this definition">¶</a></dt>
<dd><p>Return true if <em>p</em> is a list object or an instance of a subtype of the list
type.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.2: </span>Allowed subtypes to be accepted.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_CheckExact">
int <tt class="descname">PyList_CheckExact</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*p</em><big>)</big><a class="headerlink" href="#PyList_CheckExact" title="Permalink to this definition">¶</a></dt>
<dd><p>Return true if <em>p</em> is a list object, but not an instance of a subtype of
the list type.</p>
<p class="versionadded">
<span class="versionmodified">New in version 2.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="PyList_New">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyList_New</tt><big>(</big>Py_ssize_t<em>&nbsp;len</em><big>)</big><a class="headerlink" href="#PyList_New" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Return a new list of length <em>len</em> on success, or <em>NULL</em> on failure.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If <em>len</em> is greater than zero, the returned list object&#8217;s items are
set to <tt class="docutils literal"><span class="pre">NULL</span></tt>.  Thus you cannot use abstract API functions such as
<a class="reference internal" href="sequence.html#PySequence_SetItem" title="PySequence_SetItem"><tt class="xref c c-func docutils literal"><span class="pre">PySequence_SetItem()</span></tt></a>  or expose the object to Python code before
setting all items to a real object with <a class="reference internal" href="#PyList_SetItem" title="PyList_SetItem"><tt class="xref c c-func docutils literal"><span class="pre">PyList_SetItem()</span></tt></a>.</p>
</div>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>This function used an <tt class="xref c c-type docutils literal"><span class="pre">int</span></tt> for <em>size</em>. This might require
changes in your code for properly supporting 64-bit systems.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_Size">
Py_ssize_t <tt class="descname">PyList_Size</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em><big>)</big><a class="headerlink" href="#PyList_Size" title="Permalink to this definition">¶</a></dt>
<dd><p id="index-1">Return the length of the list object in <em>list</em>; this is equivalent to
<tt class="docutils literal"><span class="pre">len(list)</span></tt> on a list object.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>This function returned an <tt class="xref c c-type docutils literal"><span class="pre">int</span></tt>. This might require changes in
your code for properly supporting 64-bit systems.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_GET_SIZE">
Py_ssize_t <tt class="descname">PyList_GET_SIZE</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em><big>)</big><a class="headerlink" href="#PyList_GET_SIZE" title="Permalink to this definition">¶</a></dt>
<dd><p>Macro form of <a class="reference internal" href="#PyList_Size" title="PyList_Size"><tt class="xref c c-func docutils literal"><span class="pre">PyList_Size()</span></tt></a> without error checking.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>This macro returned an <tt class="xref c c-type docutils literal"><span class="pre">int</span></tt>. This might require changes in your
code for properly supporting 64-bit systems.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_GetItem">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyList_GetItem</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em>, Py_ssize_t<em>&nbsp;index</em><big>)</big><a class="headerlink" href="#PyList_GetItem" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Borrowed reference.</em><p>Return the object at position <em>index</em> in the list pointed to by <em>list</em>.  The
position must be positive, indexing from the end of the list is not
supported.  If <em>index</em> is out of bounds, return <em>NULL</em> and set an
<a class="reference internal" href="../library/exceptions.html#exceptions.IndexError" title="exceptions.IndexError"><tt class="xref py py-exc docutils literal"><span class="pre">IndexError</span></tt></a> exception.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>This function used an <tt class="xref c c-type docutils literal"><span class="pre">int</span></tt> for <em>index</em>. This might require
changes in your code for properly supporting 64-bit systems.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_GET_ITEM">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyList_GET_ITEM</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em>, Py_ssize_t<em>&nbsp;i</em><big>)</big><a class="headerlink" href="#PyList_GET_ITEM" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: Borrowed reference.</em><p>Macro form of <a class="reference internal" href="#PyList_GetItem" title="PyList_GetItem"><tt class="xref c c-func docutils literal"><span class="pre">PyList_GetItem()</span></tt></a> without error checking.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>This macro used an <tt class="xref c c-type docutils literal"><span class="pre">int</span></tt> for <em>i</em>. This might require changes in
your code for properly supporting 64-bit systems.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_SetItem">
int <tt class="descname">PyList_SetItem</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em>, Py_ssize_t<em>&nbsp;index</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*item</em><big>)</big><a class="headerlink" href="#PyList_SetItem" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the item at index <em>index</em> in list to <em>item</em>.  Return <tt class="docutils literal"><span class="pre">0</span></tt> on success
or <tt class="docutils literal"><span class="pre">-1</span></tt> on failure.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This function &#8220;steals&#8221; a reference to <em>item</em> and discards a reference to
an item already in the list at the affected position.</p>
</div>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>This function used an <tt class="xref c c-type docutils literal"><span class="pre">int</span></tt> for <em>index</em>. This might require
changes in your code for properly supporting 64-bit systems.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_SET_ITEM">
void <tt class="descname">PyList_SET_ITEM</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em>, Py_ssize_t<em>&nbsp;i</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*o</em><big>)</big><a class="headerlink" href="#PyList_SET_ITEM" title="Permalink to this definition">¶</a></dt>
<dd><p>Macro form of <a class="reference internal" href="#PyList_SetItem" title="PyList_SetItem"><tt class="xref c c-func docutils literal"><span class="pre">PyList_SetItem()</span></tt></a> without error checking. This is
normally only used to fill in new lists where there is no previous content.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This macro &#8220;steals&#8221; a reference to <em>item</em>, and, unlike
<a class="reference internal" href="#PyList_SetItem" title="PyList_SetItem"><tt class="xref c c-func docutils literal"><span class="pre">PyList_SetItem()</span></tt></a>, does <em>not</em> discard a reference to any item that
it being replaced; any reference in <em>list</em> at position <em>i</em> will be
leaked.</p>
</div>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>This macro used an <tt class="xref c c-type docutils literal"><span class="pre">int</span></tt> for <em>i</em>. This might require
changes in your code for properly supporting 64-bit systems.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_Insert">
int <tt class="descname">PyList_Insert</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em>, Py_ssize_t<em>&nbsp;index</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*item</em><big>)</big><a class="headerlink" href="#PyList_Insert" title="Permalink to this definition">¶</a></dt>
<dd><p>Insert the item <em>item</em> into list <em>list</em> in front of index <em>index</em>.  Return
<tt class="docutils literal"><span class="pre">0</span></tt> if successful; return <tt class="docutils literal"><span class="pre">-1</span></tt> and set an exception if unsuccessful.
Analogous to <tt class="docutils literal"><span class="pre">list.insert(index,</span> <span class="pre">item)</span></tt>.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>This function used an <tt class="xref c c-type docutils literal"><span class="pre">int</span></tt> for <em>index</em>. This might require
changes in your code for properly supporting 64-bit systems.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_Append">
int <tt class="descname">PyList_Append</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*item</em><big>)</big><a class="headerlink" href="#PyList_Append" title="Permalink to this definition">¶</a></dt>
<dd><p>Append the object <em>item</em> at the end of list <em>list</em>. Return <tt class="docutils literal"><span class="pre">0</span></tt> if
successful; return <tt class="docutils literal"><span class="pre">-1</span></tt> and set an exception if unsuccessful.  Analogous
to <tt class="docutils literal"><span class="pre">list.append(item)</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_GetSlice">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyList_GetSlice</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em>, Py_ssize_t<em>&nbsp;low</em>, Py_ssize_t<em>&nbsp;high</em><big>)</big><a class="headerlink" href="#PyList_GetSlice" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Return a list of the objects in <em>list</em> containing the objects <em>between</em> <em>low</em>
and <em>high</em>.  Return <em>NULL</em> and set an exception if unsuccessful.  Analogous
to <tt class="docutils literal"><span class="pre">list[low:high]</span></tt>.  Negative indices, as when slicing from Python, are not
supported.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>This function used an <tt class="xref c c-type docutils literal"><span class="pre">int</span></tt> for <em>low</em> and <em>high</em>. This might
require changes in your code for properly supporting 64-bit systems.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_SetSlice">
int <tt class="descname">PyList_SetSlice</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em>, Py_ssize_t<em>&nbsp;low</em>, Py_ssize_t<em>&nbsp;high</em>, <a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*itemlist</em><big>)</big><a class="headerlink" href="#PyList_SetSlice" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the slice of <em>list</em> between <em>low</em> and <em>high</em> to the contents of
<em>itemlist</em>.  Analogous to <tt class="docutils literal"><span class="pre">list[low:high]</span> <span class="pre">=</span> <span class="pre">itemlist</span></tt>. The <em>itemlist</em> may
be <em>NULL</em>, indicating the assignment of an empty list (slice deletion).
Return <tt class="docutils literal"><span class="pre">0</span></tt> on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on failure.  Negative indices, as when
slicing from Python, are not supported.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 2.5: </span>This function used an <tt class="xref c c-type docutils literal"><span class="pre">int</span></tt> for <em>low</em> and <em>high</em>. This might
require changes in your code for properly supporting 64-bit systems.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_Sort">
int <tt class="descname">PyList_Sort</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em><big>)</big><a class="headerlink" href="#PyList_Sort" title="Permalink to this definition">¶</a></dt>
<dd><p>Sort the items of <em>list</em> in place.  Return <tt class="docutils literal"><span class="pre">0</span></tt> on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on
failure.  This is equivalent to <tt class="docutils literal"><span class="pre">list.sort()</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_Reverse">
int <tt class="descname">PyList_Reverse</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em><big>)</big><a class="headerlink" href="#PyList_Reverse" title="Permalink to this definition">¶</a></dt>
<dd><p>Reverse the items of <em>list</em> in place.  Return <tt class="docutils literal"><span class="pre">0</span></tt> on success, <tt class="docutils literal"><span class="pre">-1</span></tt> on
failure.  This is the equivalent of <tt class="docutils literal"><span class="pre">list.reverse()</span></tt>.</p>
</dd></dl>

<dl class="function">
<dt id="PyList_AsTuple">
<a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a>* <tt class="descname">PyList_AsTuple</tt><big>(</big><a class="reference internal" href="structures.html#PyObject" title="PyObject">PyObject</a><em>&nbsp;*list</em><big>)</big><a class="headerlink" href="#PyList_AsTuple" title="Permalink to this definition">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p id="index-2">Return a new tuple object containing the contents of <em>list</em>; equivalent to
<tt class="docutils literal"><span class="pre">tuple(list)</span></tt>.</p>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="tuple.html"
                        title="previous chapter">Tuple Objects</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="dict.html"
                        title="next chapter">Dictionary Objects</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/c-api/list.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="dict.html" title="Dictionary Objects"
             >next</a> |</li>
        <li class="right" >
          <a href="tuple.html" title="Tuple Objects"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="http://www.python.org/">Python</a> &raquo;</li>
        <li>
          <a href="../index.html">Python v2.7.8 documentation</a> &raquo;
        </li>

          <li><a href="index.html" >Python/C API Reference Manual</a> &raquo;</li>
          <li><a href="concrete.html" >Concrete Objects Layer</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2014, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Jun 29, 2014.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>

  </body>
</html>